﻿using MediatR;
using W.Common.Enum;
using W.Purchase.API.Application.Command.ReceivableCommand;
using W.Purchase.Domain;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.ReceivableCommandHandler
{
    public class ReceivableCreateCommandHandler : IRequestHandler<ReceivableCreateCommand, int>
    {
        private readonly IReceivableRepository _ireceivableRepository;
        public ReceivableCreateCommandHandler(IReceivableRepository ireceivableRepository)
        {
            _ireceivableRepository = ireceivableRepository;
        }

        public async Task<int> Handle(ReceivableCreateCommand request, CancellationToken cancellationToken)
        {
            return await _ireceivableRepository.AddAsync(new Domain.Receivable
            {
                ReceivableId=request.ReceivableId,
                ReceivableSerialNumber=request.ReceivableSerialNumber,
                ReceivableName=request.ReceivableName,
                FinanceTypeName=request.FinanceTypeName,
                EndDate=request.EndDate,
                Payer=request.Payer,
                Payee=request.Payee,
                ReceivableMoney=request.ReceivableMoney,
                PracticalMoey=0,
                ResidueMoney= 0,
                Status= ReceivableStatus.等待审核,
                PaymentNum=request.PaymentNum,
                Receivableremark=request.Receivableremark,
                office_id=request.office_id,
                user_id=request.user_id,
                CreateName=request.CreateName,
                CreateTime=DateTime.Now,
                IsDelete=false,
                StyleStatus="应收"
            });
        }
    }
}
